﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace pGrid
{
  class ResourceManager
  {

    public int RESTORE_COAL1;
    public int RESTORE_OIL1;
    public int RESTORE_WASTE1;
    public int RESTORE_URANIUM1;

    public int RESTORE_COAL2;
    public int RESTORE_OIL2;
    public int RESTORE_WASTE2;
    public int RESTORE_URANIUM2;

    public int RESTORE_COAL3;
    public int RESTORE_OIL3;
    public int RESTORE_WASTE3;
    public int RESTORE_URANIUM3;

    private List<Resource> m_coal;
    private List<Resource> m_oil;
    private List<Resource> m_waste;
    private List<Resource> m_uranium;

    public ResourceManager()
    {
      m_coal = new List<Resource>();
      m_oil = new List<Resource>();
      m_waste = new List<Resource>();
      m_uranium = new List<Resource>();

      for (int i = 0; i < 8; i++)
      {
        m_uranium.Add(new Resource(ResourseType.uranium, i+1));
        m_coal.Add( new Resource(ResourseType.coal, i+1));
        m_oil.Add( new Resource(ResourseType.oil, i+1));
        m_waste.Add( new Resource(ResourseType.waste, i+1));
        m_coal.Add( new Resource(ResourseType.coal, i+1));
        m_oil.Add( new Resource(ResourseType.oil, i+1));
        m_waste.Add( new Resource(ResourseType.waste, i+1));
        m_coal.Add( new Resource(ResourseType.coal, i+1));
        m_oil.Add( new Resource(ResourseType.oil, i+1));
        m_waste.Add( new Resource(ResourseType.waste, i+1));
      }
      for (int i = 5; i < 9; i++)
        m_uranium.Add( new Resource(ResourseType.uranium, 2*i));
    }

    public void SetButtons(Button[] c_list, Button[] o_list, Button[] w_list, Button[] u_list)
    {
      for (int i = 0; i < m_coal.Count(); i++)
      {
        m_coal[i].Button = c_list[i];
        m_coal[i].Visible = true;
      }
      for (int i = 0; i < m_oil.Count(); i++)
      {
        m_oil[i].Button = o_list[i];
        if (i > 5)
          m_oil[i].Visible = true;
      }
      for (int i = 0; i < m_waste.Count(); i++)
      {
        m_waste[i].Button = w_list[i];
        if (i > 17)
          m_waste[i].Visible = true;
      }
      for (int i = 0; i < m_uranium.Count(); i++)
      {
        m_uranium[i].Button = u_list[i];
        if (i > 9)
          m_uranium[i].Visible = true;
      }

    }

    public void DisplayResources()
    {
      for (int i = 0; i < m_coal.Count(); i++)
        m_coal[i].Button.Visibility = m_coal[i].Visible ? Visibility.Visible : Visibility.Hidden;
      for (int i = 0; i < m_oil.Count(); i++)
        m_oil[i].Button.Visibility = m_oil[i].Visible ? Visibility.Visible : Visibility.Hidden;
      for (int i = 0; i < m_waste.Count(); i++)
        m_waste[i].Button.Visibility = m_waste[i].Visible ? Visibility.Visible : Visibility.Hidden;
      for (int i = 0; i < m_uranium.Count(); i++)
        m_uranium[i].Button.Visibility = m_uranium[i].Visible ? Visibility.Visible : Visibility.Hidden;
    }

    public void EnableResourcesForPlayer( Player curPlayer )
    {
      for (int i = 0; i < m_coal.Count(); i++)
        m_coal[i].Button.IsEnabled = curPlayer.Money >= m_coal[i].Price && curPlayer.BuyCoal;
      for (int i = 0; i < m_oil.Count(); i++)
        m_oil[i].Button.IsEnabled = curPlayer.Money >= m_oil[i].Price && curPlayer.BuyOil;
      for (int i = 0; i < m_waste.Count(); i++)
        m_waste[i].Button.IsEnabled = curPlayer.Money >= m_waste[i].Price && curPlayer.BuyWaste;
      for (int i = 0; i < m_uranium.Count(); i++)
        m_uranium[i].Button.IsEnabled = curPlayer.Money >= m_uranium[i].Price && curPlayer.BuyUranium;
    }

  }

}
